﻿<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="asset-search-panel">
    <div>
        <%= Html.TextBox("searchByAssetBarcode", "Lookup By Asset BarCode...", New With {.class = "text"})%>
    </div>
    <div>
        <%= Html.TextBox("searchByAssetName", "Lookup By Asset Name...", New With {.class = "text"})%>
    </div>
</div>
<script type="text/javascript">

    $(document).ready(function () {
        $('#searchByAssetBarcode').bind('keydown', function (e) {
            if (e.keyCode === 13 || e.keyCode === 9) {
                var val = $('#searchByAssetBarcode').val();
                getWOByBarCode(val);
            }
        });

        $('#searchByAssetName').bind('keydown', function (e) {
            if (e.keyCode === 13 || e.keyCode === 9) {
                var val = $('#searchByAssetName').val();
                getWOByAssetName(val);
            }
        });

        $('#searchByAssetName').focus(function () {
            if ($(this).attr('value') == '' || $(this).attr('value') == 'Lookup By Asset Name...') {
                $(this).attr('value', '');
            }
            $(this).css('color', '#000');

        });
        $('#searchByAssetName').blur(function () {
            if ($(this).attr('value') == '') {
                $(this).attr('value', 'Lookup By Asset Name...');
                $(this).css('color', '#777');
            }
        });


        $('#searchByAssetBarcode').focus(function () {
            if ($(this).attr('value') == '' || $(this).attr('value') == 'Lookup By Asset BarCode...') {
                $(this).attr('value', '');
            }
            $(this).css('color', '#000');

        });
        $('#searchByAssetBarcode').blur(function () {
            if ($(this).attr('value') == '') {
                $(this).attr('value', 'Lookup By Asset BarCode...');
                $(this).css('color', '#777');
            }
        });

    });

    function getWOByBarCode(val) {
        showLoading("", true);
        jQuery.ajax({
            type: 'POST',
            data: { barcode: val },
            url: '<%= Url.Content("~/WorkOrder/GetLatestWorkOrderLinkByAssetBarCode") %>',
            success: function (jsonData) {
                if (jsonData.Result != "") {
                    window.location = '<%= Url.Content("~/") %>' + jsonData.Result;
                }
                else {
                    alert("Service is unavailable!");
                }
            }
        });
    }

    function getWOByAssetName(val) {
        showLoading("", true);
        jQuery.ajax({
            type: 'POST',
            data: { name: val },
            url: '<%= Url.Content("~/WorkOrder/GetLatestWorkOrderLinkByAssetName") %>',
            success: function (jsonData) {
                if (jsonData.Result != "") {
                    window.location = '<%= Url.Content("~/") %>' + jsonData.Result;
                }
                else {
                    alert("Service is unavailable!");
                }
            }
        });
    }
    

</script>